package org.hoyi.util;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

/**
 *
 * @author ljb 84024551@qq.com 2015年5月22日
 *
 */
public final class Util
{
	public static String getDomainWithSeparator(HttpServletRequest request)
	{
		StringBuffer url = request.getRequestURL();
		String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getServletContext().getContextPath()).append("/").toString();
		return tempContextUrl;
	}

	public static String getDomainNotWithSeparator(HttpServletRequest request)
	{
		StringBuffer url = request.getRequestURL();
		String tempContextUrl = url.delete(url.length() - request.getRequestURI().length(), url.length()).append(request.getServletContext().getContextPath()).toString();
		return tempContextUrl;
	}

	public static String getFullDomainUrl(HttpServletRequest request, String url)
	{
		if (StringUtils.isNotEmpty(url))
		{
			String newUrl = "";
			if (url.startsWith("/"))
				newUrl = getDomainNotWithSeparator(request) + url;
			else
				newUrl = getDomainWithSeparator(request) + url;
			return newUrl;
		}
		return url;
	}
	
	 
	  public static String FirstUpToParscal(String str)
	  {
	    char[] ch = str.toCharArray();
	    for (int i = 0; i < ch.length; i++) {
	      if (i == 0)
	        ch[0] = Character.toUpperCase(ch[0]);
	    }
	    StringBuffer a = new StringBuffer();
	    a.append(ch);
	    return a.toString();
	  }
}
